{% extends "templates/atnet_base.html" %}

{% block csslink %}
{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$('#accounts').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": false,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			if (aData[0] == 'acc') {
				$('td:eq(0)', nRow).html('<b>' + aData[1] + '</b>');
				$('td:eq(1)', nRow).html('<b>' + aData[2] + '</b>');
				$('td:eq(2)', nRow).html('');
				$('td:eq(3)', nRow).html('');
			}
			else {
				$('td:eq(3)', nRow).html('<a href="javascript:void(0);" id="' + aData[4] + '">{{ _("Edit") }}</a>');
			}
		},
		 "aoColumnDefs": [
		                  { "bVisible": false, "aTargets": [ 0 ] },
		                  { "sClass": "aright", "aTargets": [ 1 ] }
		                  ]
	});
	
	$('#add-account').live('click', function(){
		$(this).LaunchPopup({
			TableId: '#accounts',
			DivId: '#dialog-form',
			FormId: '#generated-form',
			UrlForm: "{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='add') }}",
			Mode: 'add',
			Title: '{{ _("Add account") }}',
			UrlReturn: "{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='list') }}"
		})
	});
	
	$('#accounts tbody tr a').live('click', function(e) {
		$(this).LaunchPopup({
			TableId: '#accounts',
			DivId: '#dialog-form',
			FormId: '#generated-form',
			UrlForm:"{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
			Mode: 'edit',
			Title: '{{ _("Edit account") }}',
			UrlReturn: "{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='list') }}"
		})
	});
});
</script>

{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block page_name %}
{{ content_header }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_parametrage_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	<p>
	<a href="javascript:void(0);" id="add-account">{{ _('Add subaccount') }}</a> ||  
	<a href="{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='predefine') }}">{{ _('Set or restore default list of subaccounts') }}</a>
	</p>
	<div id="demo">
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="accounts" width="100%">
		<thead>
			<tr>
				<th></th>
				<th>{{ _(fields.code) }}</th>
				<th>{{ _(fields.name) }}</th>
				<th>{{ _(fields.balance) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th></th>
				<th>{{ _(fields.code) }}</th>
				<th>{{ _(fields.name) }}</th>
				<th>{{ _(fields.balance) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>			
{% endblock %}
